package guoanmaker.operator.business.repository;

import java.util.Collection;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


import guoanmaker.operator.business.model.ProviderBusiness;



public interface ProviderBusinessRepository  extends  JpaRepository<ProviderBusiness, String>, JpaSpecificationExecutor<ProviderBusiness>{

	
	@Query("select  b from  ProviderBusiness b join b.personalUser u where u.id=b.personalUser.id and b.id=:id")
	public  ProviderBusiness viewmerchantinfo(@Param("id") String id);
	
	@Query("select b from  ProviderBusiness b inner join b.personalUser u where  u.id=:id ")
	public  List<ProviderBusiness> viewmerUchantinfo(@Param("id") String id);
	
	@Query("select  b from  ProviderBusiness b left join b.personalUser u where u.isProvider='2' or u.isProvider='4' ")
	public  List<ProviderBusiness>   selectAllbusinessinfo();
	
	@Query("select  b  from ProviderBusiness b where b.id=:id")
	public  ProviderBusiness  selectByid(@Param("id") String id);
	@Query("select  b  from ProviderBusiness b left join b.personalUser u where u.isProvider=2 and b.commoditys like  CONCAT('%',:serverid,'%') ")
	public List<ProviderBusiness> findByseverid(@Param("serverid") String serverid);
	
	
	@Query("select  b  from ProviderBusiness b left join b.personalUser u where b.busNumber=:busNumber and u.username=:username")
	public  ProviderBusiness  selectValidateBybusCodeAndUsername(@Param("busNumber") String busNumber,@Param("username") String username);
	
	@Query("select b from  ProviderBusiness b inner join b.personalUser u where  u.isProvider=2 and b.busNumber=:busNumber ")
	public  List<ProviderBusiness> selectBusinessAndUser(@Param("busNumber") String busNumber);
	
	@Query("select  b  from ProviderBusiness b where b.commoditys like %:id%")
	public  List<ProviderBusiness>  selectByServerId(@Param("id") String id);
}
